// 实现对施工通告Construction_Notice表的增查
const { Construction_Notice } = require('../model/create_tables')

/* 新增施工公告 */
const addNotice = async (noticeObj) => {
  const res = await Construction_Notice.create(noticeObj)
  return {
    status: 1,
    message: '新增施工公告成功',
    data: res.toJSON(),
  }
}

/* 查询公告 */
// 查询所有公告
const getAllNotice = async () => {
  const res = await Construction_Notice.findAll()
  if (res.length >= 2) {
    return {
      message: '找到多条公告',
      data: res.map((notice) => notice.toJSON()),
      status: 1,
    }
  } else if (res.length == 1) {
    return {
      message: '找到一条公告',
      data: res[0].toJSON(),
      status: 1,
    }
  } else {
    return {
      message: '未找到公告数据',
      status: 0,
    }
  }
}

exports.addNotice = addNotice
exports.getAllNotice = getAllNotice
